﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CRMFramework;
using CRMEntity;


namespace CRMWeb
{
    public partial class ClientProfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBindToGridView();

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            int appID = Convert.ToInt32(txtClientID.Text);
            string firstName1 = txtFirstName1.Text;
            string firstName2 = txtFirstName2.Text;
            string middleName1 = txtMiddleName1.Text;
            string middleName2 = txtMiddleName2.Text;
            string surName1 = txtSurname1.Text;
            string surName2 = txtSurName2.Text;

            string query = "Insert Into app_info (app_id, app_FirstName1,app_FirstName2, app_middleName1,app_middlename2,app_surname1,app_surname2) value(" +
                appID + ",'" + firstName1 + "','" + firstName2 + "','" + middleName1 + "','" + middleName2 + "','" + surName1 + "','" + surName2 + "')";

            DBhelper.ExecuteNonQuery(query);
          
            DataBindToGridView();
        }

        private void DataBindToGridView()
        {
            string query = "select app_FirstName1,app_FirstName2,app_MiddleName1,app_MiddleName2,app_Surname1,app_Surname2,app_Date,app_Time from app_info";
            DataTable dt = DBhelper.ExecuteDatasetQuery(query).Tables[0];

             List<Client> listAllclient =new List<Client> ();
            foreach (DataRow dr in dt.Rows)
            {
                Client newclient = new Client();
               
                    //newclient.AppID =(int) dr["app_FirstName1"];
                    newclient.App_FirstName1 = (String)dr["app_FirstName1"];
                    newclient.App_FirstName2 = (String)dr["app_FirstName2"];
                    newclient.App_MiddleName1 = (String)dr["app_MiddleName1"];
                    newclient.App_MiddleName2 = (String)dr["app_MiddleName2"];
                    newclient.App_SurName1 = (String)dr["app_Surname1"];
                    newclient.App_SurName2 = (String)dr["app_Surname2"];
                    listAllclient.Add(newclient);
                
                listAllclient.Add(newclient);
            }
            GridView1.DataSource = listAllclient;
            GridView1.DataBind();

        }
    }
}